package com.etcfg.etlaunch.ui;

import java.awt.event.ActionEvent;

import javax.swing.AbstractAction;
import javax.swing.JOptionPane;

import com.etcfg.etlaunch.ETLauncherApplication;
import com.etcfg.etlaunch.ETServer;

public class ChangePasswordAction extends AbstractAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = -3143797828516902150L;
	private MainWindow mainWindow;
	private ETLauncherApplication application;

	public ChangePasswordAction(final MainWindow window,
			ETLauncherApplication application) {
		this.application = application;
		mainWindow = window;
		putValue(NAME, "Change password");

	}

	@Override
	public void actionPerformed(ActionEvent e) {

		ETServer etServer = mainWindow.getSelectedEtServer();
		if (etServer == null) {
			return;
		}
		String showInputDialog = JOptionPane.showInputDialog(mainWindow
				.getFrame(), "Change server password", etServer.getPassword());
		if (showInputDialog != null) {
			etServer.setPassword(showInputDialog);
			application.saveServerList();
		}

	}

}
